﻿@{
    Bundle("jquery_validate");
}

<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery('@ID("#form")').validate({
            rules: {
                operationName: {
                    required: true
                },
                file: {
                    required: true
                }
            }
        });
        jQuery.ajax({
            type: 'post',
            url: '@Url.Action(Loc.Act("Formats"))',
            dataType: 'json',
            success: function (rsp) {
                jQuery('@ID("#ddl_format")').empty();
                jQuery.each(rsp, function (k, v) {
                    jQuery('@ID("#ddl_format")').append('<option value=' + v.id + '>' + v.value + '</option>');
                });
            }
        });
        jQuery('@ID("#btn_add_property")').click(function (event) {
            event.preventDefault();
            var propNum = jQuery('@ID("#table_properties") tr').length;
            jQuery('@ID("#table_properties")').append('<tr>' +
                '<td><input type="text" name="properties[' + propNum + '].Key" /></td>' +
                '<td><input type="text" name="properties[' + propNum + '].Value" /></td>' +
                '</tr>');
        });
    });
</script>
<form id="@ID("form")" action="@Url.Action(Loc.Act("Import"))" method="post" enctype="multipart/form-data">
    <input type="hidden" name="flags" value="None" />
    <table>
        <tr>
            <td>
                <label>@T(Res.Name("Format"))</label>
            </td>
            <td>
                <select id="@ID("ddl_format")" name="formatID"></select>
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Operation"))</label>
            </td>
            <td>
                <input type="text" name="name" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("File"))</label>
            </td>
            <td>
                <input type="file" name="file" />
            </td>
        </tr>
    </table>
    <hr />
    <table id="@ID("table_properties")">
        <tr>
            <td>
                <input type="text" name="properties[0].Key" />
            </td>
            <td>
                <input type="text" name="properties[0].Value" />
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="properties[1].Key" />
            </td>
            <td>
                <input type="text" name="properties[1].Value" />
            </td>
        </tr>
        <tr>
            <td>
                <input type="text" name="properties[2].Key" />
            </td>
            <td>
                <input type="text" name="properties[2].Value" />
            </td>
        </tr>
    </table>
    <ul class="bar toolbar">
        <li><button id="@ID("btn_add_property")" class="button">+</button></li>
        <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
    </ul>
</form>